<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<script src="js/data.js"></script>
		<script src="js/qrcode.js"></script>
		<script src="js/jquery.min.js"></script>
		<script src="js/base64.js"></script>
		<link rel="stylesheet" href="js/index.css">
	</head>
	<body>
		<div>打卡帐号:<p class="info" id="account"></p></div>
		<div>打卡人:<p class="info" id="name"></p></div>
		<div>打卡时间:<p class="info" id="time"></p></div>
		<div>银行电话:<p class="info" id="bankPhone"></p></div>
		<div>网点名:<p class="info" id="bankName"></p></div> 
		
		<!-- 按钮组 -->
		<div style="margin-top: 20px;">
			<button class="nextBtn" onclick="upBtnClick()">上一个</button>
			<button class="nextBtn" onclick="nextBtnClick()" style="margin-left: 20px;">下一个</button>
			<button class="nextBtn" onclick="getCode()" style="margin-left: 20px;">刷新</button>
			<select id="selectTime" onchange="changeSelectTime()">
				<option value="0">默认</option>
				<option value="1">上午</option>
				<option value="2">下午</option>
			</select>
		</div>
		
		<!-- 显示二维码 -->
		<div id="qrcode" style="margin-top: 40px;"></div>
	</body>
	
	<script>
		var _codeView
		getCode()
		
		//设置时间
		function changeSelectTime(){
			getCode()
		} 
		
		function reoloadTime(){
			var value = $('#selectTime').val()
			
			if (value == 0) {
				checkUpOrDown()
				return
			} else if (value == 1) {
				_isUp = true
			} else {
				_isUp =false
			}
			
			$('#time').text(_isUp ? '上午' : '下午')
		}
		
		//检查是上午还是下午
		function checkUpOrDown(){
			var date = new Date()
			// 获取当前小时
			let hours = date.getHours()

			if (hours < 12) {
			_isUp = true
			} else { 
			_isUp =false
			}
			
			$('#time').text(_isUp ? '上午' : '下午')
		}
		
		//获取二维码
		function getCode(){ 
			//刷新时间状态 
			reoloadTime()
			
			//当前打卡人信息
			var userData = _userArr[_doneIndex]
			//打卡人帐号
			$('#account').text(userData['id'])
			$('#name').text(userData['name'])
			
			//获取手机号
			var phoneData = _isUp ? userData['upPhone'] : userData['downPhone']
			$('#bankPhone').text(phoneData)
			
			//获取打卡数据
			var bankData = _bankUserInfoDic[phoneData]
			$('#bankName').text(bankData['bankName'])
			
			//获取二维码数据
			var codeData = bankData['data']
			//修改时间
			codeData['creatTime'] = new Date().getTime()
			
			//code内容
			var code = base64encode(encodeURI(JSON.stringify(codeData)))
			//生成图片
			if (_codeView == null) {
				_codeView = new QRCode(document.getElementById("qrcode"), {
					text: code,
					width: 400,
					height: 400,
					colorDark : "#000000",
					colorLight : "#ffffff",
					correctLevel : QRCode.CorrectLevel.H
				});
			} else {
				_codeView.clear()
				_codeView.makeCode(code)
			}
			

		}
		
		//上一个
		function upBtnClick(){
			_doneIndex = _doneIndex - 1
			if (_doneIndex < 0) {
				_doneIndex =  _userArr.length - 1
			}
			
			getCode()
		}
		
		//下一个
		function nextBtnClick(){
			_doneIndex = _doneIndex + 1
			if (_doneIndex >= _userArr.length) {
				_doneIndex = 0
			}
			
			getCode()
		}
		
	</script>
</html>
